package com.mz.ieann.aide.main.flutter

import android.content.Context
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.mz.ieann.aide.base.BaseActivity
import com.mz.ieann.aide.utils.FlutterHelper
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) 2020 wasu company, All rights reserved.
 * <p>------------------------------------------------------
 * <p>
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2023/6/28
 */
class FlutterTestActivity: BaseActivity() {

    private val flutterEngine: FlutterEngine by lazy {
        initFlutterEngine(this)
    }

    private fun initFlutterEngine(
        context: Context,
        dartVmArgs: Array<String>? = null
    ) = FlutterEngine(context, dartVmArgs).apply {

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent { AddFlutterTest() }
    }

    @Preview(showSystemUi = true)
    @Composable
    private fun AddFlutterTest(){
        Column(horizontalAlignment = Alignment.CenterHorizontally) {
            Button(onClick = {
                FlutterHelper.startNewEngine(this@FlutterTestActivity)
            }) {
                Text(text = "点我跳转无缓存engine")
            }
            Spacer(modifier = Modifier.height(20.dp))
            Button(onClick = {
                FlutterHelper.startCacheEngine(this@FlutterTestActivity)
            }) {
                Text(text = "点我跳转有缓存engine")
            }
            Spacer(modifier = Modifier.height(20.dp))
            Button(onClick = {
                FlutterHelper.startCacheEngine(this@FlutterTestActivity, "login")
            }) {
                Text(text = "点我跳转指定route页面")
            }
            Spacer(modifier = Modifier.height(20.dp))
            Button(onClick = {

            }) {
                Text(text = "点我跳转指定route并携带参数页面")
            }
        }
    }

}